package com.blog.service.impl;

import com.blog.mapper.TagMapper;
import com.blog.pojo.Tag;
import com.blog.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class TagServiceImpl implements TagService {

    @Autowired
    private TagMapper tagMapper;

    // 查看所有标签
    @Override
    public List<Tag> list() {
        List<Tag> tagList = tagMapper.list();
        return tagList;
    }

    // 添加标签
    @Override
    public void add(Tag tag) {
        tagMapper.insert(tag);
    }


    // 删除标签
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(Integer id) {
        tagMapper.deleteById(id);
        tagMapper.deleteArticleTagByTagId(id);
        tagMapper.deleteHobbyByTagId(id);
    }

}
